﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using MySql.Data.MySqlClient;


namespace ATM
{
    public partial class inter_face : Form
    {
        AccountLogic cal = new AccountLogic();
        //AccountDB d = new AccountDB();
        public string x;
        public inter_face(string acc)
        {
            InitializeComponent();
            x = acc;
        }
        public static string name, accounN, balnce, email;

        private void balanceInquiry_Click(object sender, EventArgs e)
        {
            this.Hide();
            BalanceInquiry form = new BalanceInquiry(x);
            form.Show(); 

        }
        //** Should provide backup details about it
        private void withdraw_Click(object sender, EventArgs e)
        {
            this.Hide();
            withdraw frm = new withdraw(x);
            frm.Show();
        }
        //** Should provide backup details about it    
        private void Deposit_Click(object sender, EventArgs e)
        {
            this.Hide();
            deposit frm = new deposit(x);
            frm.Show();
        }

        private void account_details_Click(object sender, EventArgs e)//account details
        {
            displayHistory.Hide();
            AccountLogic.grid = dataGridView1;
            cal.callinter(x);

        
        }

        private void Exit_Click(object sender, EventArgs e)
        {
            welcom w = new welcom();
            w.Show();
            this.Hide();
        }

     

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
           /* if (e.RowIndex >= 0)
            {
                DataGridViewRow row = dataGridView1.Rows[e.RowIndex];
                nlabel2.Text = row.Cells["Name"].Value.ToString();
                elabel3.Text = row.Cells["Email"].Value.ToString();
                alabel4.Text = row.Cells["Account_Number"].Value.ToString();
                blabel5.Text = row.Cells["balance"].Value.ToString();

            }*/
        }

        private void print_Click(object sender, EventArgs e)
        {
            Print_PDF pd = new Print_PDF();

            if (dataGridView1.ColumnCount != 0)
            {
                DataGridViewRow row = dataGridView1.Rows[0];
                name = row.Cells["Name"].Value.ToString();
                email = row.Cells["Email"].Value.ToString();
                accounN = row.Cells["Account_Number"].Value.ToString();
                balnce = row.Cells["balance"].Value.ToString();
                if (name != "" && email != "" && accounN != "" && balnce != "")
                    pd.print_event();
                else
                    MessageBox.Show("wrong !!");
            }
            else
                MessageBox.Show("You must show your account details first sir !!");
            
           
            /*Print_PDF pd = new Print_PDF();
            pd.print_event();*/
        }
        //** Should provide backup details about it
        private void bay_bill_Click(object sender, EventArgs e)
        {
            this.Hide();
            companies frm = new companies(x);
            frm.Show();
        }

        private void Currency_transfer_Click(object sender, EventArgs e)
        {
            CurrencyTransIntro c = new CurrencyTransIntro(x);
           // cal cu = new currencyToPound(x);
            c.Show();
            this.Hide();
        }

        private void displayHistory_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            
        }

     

        private void showHistory_Click(object sender, EventArgs e)
        {

            displayHistory.Show();
            string connectionString = "datasource=localhost;port=3306;username=root;password=1234"; //Set your MySQL connection string here.
            string query = "SELECT * FROM atm.History where Account_Number='" + this.x + "';"; // set query to fetch data "Select * from  tabelname"; 
            using (MySqlConnection conn = new MySqlConnection(connectionString))
            {
                using (MySqlDataAdapter adapter = new MySqlDataAdapter(query, conn))
                {
                    DataSet ds = new DataSet();
                    adapter.Fill(ds);
                    displayHistory.DataSource = ds.Tables[0];
                }
            }
        }


           
        //** Should provide backup details about it
        private void Transfer_balance_Click(object sender, EventArgs e)
        {
            TransferBalnace t = new TransferBalnace(x);
            t.Show();
            this.Hide();
        }

        private void pictureBox1_Click(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {

        }
    }
}
